package com.lhj.myapplication.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 全局配置开启跨域
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        WebMvcConfigurer.super.addCorsMappings(registry);
        registry.addMapping("/**")
                //.allowedOrigins("*")
                //设置允许跨域请求的域名
                .allowedOriginPatterns("*")
                //设置允许的方法
                .allowedMethods("GET","POST","HEAD","PUT","DELETE","OPTIONS")
                // 是否允许证书（cookies）
                .allowCredentials(true)
                //跨域允许时间
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
